package com.app.login.dao.impl;

import com.app.login.dao.LoginDao;
import com.app.login.model.Login;
import com.app.sysmodule.dao.impl.BaseDaoImpl;
import com.app.sysmodule.exception.DBException;
import org.hibernate.Query;

import java.util.List;

/**
 * Created by song on 2018/1/9.
 */
public class LoginDaoImpl extends BaseDaoImpl<Login> implements LoginDao {
    public Login getUser(String username, String password) throws DBException {
        try {
            String hql=" from Login where userName=(:username) and password=(:password)";
            Query query = this.getSession().createQuery(hql).setParameter("username",username).setParameter("password",password);
            List<Login> list = query.list();
            if(null != list && list.size()>0){
                return (Login)list.get(0);
            }
        }catch (Exception e){
            throw new DBException(e.getMessage());
        }
        return null;
    }
}
